package com.doit.demo02.test;

public class test02 {
    public static void main(String[] args) {
        //模仿Arraylist内部添加元素的方法
        String [] arr = {"柳岩","唐嫣","赵露思",null,null,null};
        int index = 2;//增加元素的位置
        int size = 3;
        int move = size-index;
        System.arraycopy(arr,index,arr,index+1,move);
        arr[index]="段红光";
        size++;
        for(String s:arr)
        {
            System.out.println(s);
        }

        System.out.println("+++++++++++++++++++++++");
        //模仿Arraylist内部删除元素的方法
        String [] arr2 = {"柳岩","唐嫣","赵露思"};
        int index2 = 1;//删除元素的位置
        int size2 = 3;
        int move2 = size-index-1;
        System.arraycopy(arr2,index2+1,arr2,index2,move2);
        arr2[--size2]=null;
        for(String s:arr2)
        {
            System.out.println(s);
        }
    }
}
